//
//  MainTabBarController.m
//  YIChuSeller
//
//  Created by xsj on 2018/11/22.
//  Copyright © 2018年 xiangshengjun. All rights reserved.
//

#import "GXMainTabBarController.h"
#import "GXMainNavigationController.h"
#import "GXOrderViewController.h"
#import "GXHomeViewController.h"
@interface GXMainTabBarController ()<UITabBarControllerDelegate>

@end

@implementation GXMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    [self setupTabBar];
    [self addChildViewControllers];
}

- (void)setupTabBar
{
    [[UITabBarItem appearance] setTitleTextAttributes:@{
                                                        NSFontAttributeName: [UIFont systemFontOfSize:14],
                                                        NSForegroundColorAttributeName : RGBColor(197, 195, 196)
                                                        } forState:UIControlStateNormal];
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{
                                                        NSForegroundColorAttributeName : kGlobalButtonColor
                                                        } forState:UIControlStateSelected];
    
    
}

- (void)addChildViewControllers
{
    GXOrderViewController *orderVC = [[GXOrderViewController alloc]init];
    [self addChildViewController:orderVC withImageName:@"tabbar_order" title:@"订单"];
    
    GXHomeViewController *shopVC = [[GXHomeViewController alloc]init];
    [self addChildViewController:shopVC withImageName:@"tabbar_shop" title:@"店铺"];
}


- (void)addChildViewController:(UIViewController *)childController withImageName:(NSString *)icon title:(NSString *)title
{
    UITabBarItem *item = childController.tabBarItem;
    
    childController.title = title;
    
    NSString *selectIcon = [icon stringByAppendingString:@"_selected"];
    UIImage *iconImage = [[UIImage imageNamed:icon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *selectIconImage = [[UIImage imageNamed:selectIcon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    item.image = iconImage;
    item.selectedImage = selectIconImage;
    
    GXMainNavigationController *nav = [[GXMainNavigationController alloc]initWithRootViewController:childController];
    [self addChildViewController:nav];
}

@end
